﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;


namespace Heaven.Showcase.Demos
{
    /// <summary>
    /// Class represents an exception handler (or dump collector?)
    /// </summary>
    public class RenderExceptionHandler
    {
        /// <summary>
        /// Dumps data and shows in wordpad
        /// </summary>
        /// <param name="exception">Исключение, которое возникло при рендеринге</param>
        public static void DumpAndShow(Exception exception)
        {
            string dumppath = System.IO.Path.GetTempPath() + "Dump " + DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture).Replace('/','.').Replace(':','.') + ".rtf";
            System.IO.File.WriteAllText(dumppath, GetExceptionInfo(exception));
            //Process.Start(dumppath);
        }

        static string GetExceptionInfo(Exception exception)
        {
            string text = "Message: " + exception.Message + ".\n";
            if(exception.StackTrace != "") text += "Stacktrace:\n" + exception.StackTrace;
            if (exception.InnerException != null) return text + "\n\n" + GetExceptionInfo(exception.InnerException);
            else return text;
        }
    }
}
